package com.itbaizhan.shopping_common.result;


import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: shopping
 * @ClassName GlobalExceptionHandler
 * @description: 统一异常处理器
 * @author: jing
 * @create: 2025-06-12 22:51
 **/

@RestController
public class GlobalExceptionHandler {

    //处理业务异常
    @ExceptionHandler(BaseException.class)
    public BaseResult defaultExceptionHandler(BaseException e){
        BaseResult baseResult = new BaseResult(e.getCode(), e.getMsg(), null);
        return baseResult;
    }

    //处理系统异常
    @ExceptionHandler(Exception.class)
    public BaseResult defaultExceptionHandler(Exception e){
        e.printStackTrace();
        BaseResult baseResult = new BaseResult(CodeEnum.SYSTEM_ERROR.getCode(), CodeEnum.SYSTEM_ERROR.getMessage(), null);
        return baseResult;
    }
}
